#!/usr/bin/python
# -*- coding: utf-8 -*-

from PyQt4 import QtCore, QtGui

from pylot.core import (Collection, LEVELS)

from _pylot.qtgui.interfaces.widgetinterface import WidgetInterface
from _pylot.qtgui.misc import load_designer_file

_GuiAutoPrefs, WidgetClass = load_designer_file(u'auto_preferences.ui')
class GuiAutoPrefs(WidgetClass, _GuiAutoPrefs, WidgetInterface):
  def __init__(self, tabs=False, handler=None):
    WidgetClass.__init__(self)
    WidgetInterface.__init__(self, handler)
    self.setupUi(self)
    self._tabs = tabs
    if self._tabs is True :
      self.tab_widgets = QtGui.QTabWidget()
      self.main_layout.addWidget(self.tab_widgets)

  def addPrefWidget(self, widget):
    u"""
    :param widget: a WidgetInterface widget
    """
    self.addpyLotWidget(widget)
    if self._tabs is True :
      self.tab_widgets.addTab(widget, widget.windowTitle())
    else :
      self.main_layout.addWidget(widget)

  def _translate(self):
    if self._tabs is True :
      for idx in range(self.tab_widgets.count()) :
        widget = self.tab_widgets.widget(idx)
        self.tab_widgets.setTabText(idx, widget.windowTitle())
    self._setTexts([
      (self, self.handler.alias)
      ])

